package clone;

public class Student implements Cloneable {
	private String name;
	private int age;
	private Teacher teacher;
	
	public Student(String name, int age, Teacher teacher){
		this.name = name;
		this.age = age;
		this.teacher = teacher;
	}
	
	
	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public int getAge() {
		return age;
	}


	public void setAge(int age) {
		this.age = age;
	}


	public Teacher getTeacher() {
		return teacher;
	}


	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}


	public Student clone(){
		Student student = null;
		try{
			student = (Student)super.clone();
			///**深度克隆（是为了手动复制引用类型的属性，保证克隆前后引用类型的成员属性的地址不一样）
			Teacher clone = this.teacher.clone();
			student.setTeacher(clone);			
			
		}catch(CloneNotSupportedException e){
			e.printStackTrace();
		}
		return student;
	}
}
